# 3.1 LED Blink ## 3.1.1 Overview LED Blink is one of the simplest entry-level programming projects. It only needs an LED and then upload the code This simple project helps beginners better master basic concepts. ## 3.1.2 Schematic Diagram ![6-1-2](./media/6-1-2.png) **LED lighting on:** The output current of the IO ports is limited, so the LED brightness may not be enough. Therefore, a NPN triode (Q2) is added to the circuit as a switch. We only need to add a high(low) level at the triode base pin 1 to light it up(out). **Triode on/off:** To put it simple, when the base(pin 1) receives a high level, the collector(pin 3) and the transmitter(pin 2) are connected, so then VCC passes through the current-limiting resistor to the LED and then into the triode to GND, forming a loop. At this time, LED is on. When pin 1 receives a low level, pin 3 and 2 are disconnected so the current loop cannot be formed, resulting LED off. ## 3.1.3 Code Blocks 1. ![j1](./media/j1.png) The start of the execution of a code. Codes will not run without this block. The module blocks that need to be initialized should be added below the block. 2. ![j2](./media/j2.png) Code run in here and are executing all the time (in a loop). 3. ![j3](./media/j3.png) This block controls the ON/OFF of an LED. You only need to set the pin and power level(HIGH/LOW). 4. ![j4](./media/j4.png) The delay seconds can be modified as needed. Unit: s. Some conversions: 1S=1000mS; 1mS=1000uS; For instance, if a delay of 10ms is required, input 0.01. ## 3.1.4 Test Code ## 3.1.4.1 Build Code There are two ways to upload the code: directly open the code file we provide; or manually build blocks. **Directly open the code file we provide:** 1. Click ![](./media/j68.png) and choose `Load from your computer` ![](./media/j67.png) 2. We have already downloaded the codes on computer desktop, so open the file and choose `3-1-led.sb3` **Manually build blocks:** 1. In ![events](./media/events.png), find ![j1](./media/j1.png) block. 2. In ![control](./media/control.png), find and place ![j2](./media/j2.png) block under ![j1](./media/j1.png). ![6-1-4-1-1](./media/6-1-4-1-1.png) 3. In ![image-led](./media/led.png), drag and put ![j3](./media/j3.png) block into ![j2](./media/j2.png). Set pin to IO23 and output to HIGH. ![6-1-4-1-2](./media/6-1-4-1-2.png) 4. In ![control](./media/control.png), add a delay ![j4](./media/j4.png) of 500ms. So we set it to 0.5s. ![6-1-4-1-3](./media/6-1-4-1-3.png) 5. Right-click ![j3](./media/j3.png) and you will see ![j5](./media/j5.png). Choose `Duplicate` and put the copy under ![6-1-4-1-4](./media/6-1-4-1-4.png): ![6-1-4-1-5](./media/6-1-4-1-5.png) 6. Modify ![j3](./media/j3.png) output into LOW. ![](./media/6-1-4-1-6.png) ## 3.1.4.2 Test Result After uploading code, the red LED will blink with an interval of 0.5 seconds. ## 3.1.5 Extension If you want the LED to blink more frequently, just modify the delay time in ![j4](./media/j4.png). If we set the time shorter, it will blink faster. Now let's set it to 0.25s. ## 3.1.5.1 Test Code There are two ways to upload the code: directly open the code file we provide; or manually build blocks. **Directly open the code file we provide:** 1. Click ![](./media/j68.png) and choose `Load from your computer` ![](./media/j67.png) 2. We have already downloaded the codes on computer desktop, so open the file and choose `3-1-led2.sb3` **Manually build blocks:** Build code blocks as above but set delay to 0.25. ![](./media/6-1-5-1-1.png) ## 3.1.5.2 Test Result After uploading code, the red LED will blink with an interval of 0.25 seconds. Compared to 3.1.4.1, it blinks more frequently.